package com.mall.user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.mall.user.blockhandler.TestBlockHandler;
import com.mall.user.fallbackhandler.TestFallBackHandler;
import com.mall.user.service.impl.TestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class Test {

    @Autowired
    private TestServiceImpl testService;

    @SentinelResource(value = "test1",blockHandlerClass = TestBlockHandler.class,blockHandler = "test1Handler")
    @GetMapping("/test1")
    public String test1(String flag) throws InterruptedException {
        if (flag == null) {
            Thread.sleep(5000);
        }
        return testService.test3();
    }

    @GetMapping("/test2")
    public String test2() {
        return testService.test3();
    }

    @SentinelResource(value = "testFusing",fallbackClass = TestFallBackHandler.class,fallback = "testFusingFallback")
    @GetMapping("/testFusing")
    public String testFusing(String flag) throws Exception{
        if (flag == null) {
            Thread.sleep(2000);
        }
        return "测试熔断";
    }

}
